﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.ComponentModel;
using System.Web.Configuration;
using HospitalSystem.Core;

namespace HospitalSystem
{
    public partial class regfamilyok2 : System.Web.UI.Page
    {
        private show_Image _showimage;
        private regfamilyLog _regf;
        protected void Page_Load(object sender, EventArgs e)
        {

            showsession();
            _showimage = new show_Image();

            _regf = new regfamilyLog();
            _showimage.show_Images(cid_label, Image1);



            if (Session["CID"] == null)
            {

                MessageBoxurl("กรุณากดค้นหา หรือลงทะเบียนเด็กก่อน", "findchild.aspx");

            }

            if (!IsPostBack)
            {
                
                //showlistfamily2();

                _regf.showlistfamily2(cid_label, familylist);
                _regf.showlistCarer(cid_label, Carerlist);
            }

        }




        private void MessageBoxurl(string msg, string urld)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "');" + "window.location.href='" + urld + "';" + "</script>";
            Page.Controls.Add(lbl);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["fCID"] = null;
            
            Response.Redirect("~/familyedit.aspx");  
        }



        protected void showsession()
        {
            String ShowValue = (string)Session["CID"];
            cid_label.Text = ShowValue;
            String ShowValue2 = (string)Session["LastName"];
            lname.Text = ShowValue2;

            String ShowValue3 = (string)Session["FirstName"];
            fname.Text = ShowValue3;
                        
        }

       

        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);



        }
             

        protected void Button3_Click(object sender, EventArgs e)
        {
            carertolabel();
        }



        private void carertolabel()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT fCID FROM [Carer] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", cid_label.Text);
      
            SqlDataReader reader2 = CmdSql2.ExecuteReader();



            if (reader2.Read())
            {
               fcid.Text = reader2["fCID"].ToString();

               Session["fCID"] = fcid.Text;

               Response.Redirect("~/familyeditcarer.aspx");

            }
            else
            {

            }
            conn.Close();
            reader2.Close();
        }

        protected void familylist_SelectedIndexChanged(object sender, GridViewPageEventArgs e)
        {
            familylist.PageIndex = e.NewPageIndex;
            _regf.showlistfamily2(cid_label, familylist); 
        }







    }
}